import java.util.HashSet;
import java.util.Set;

public class Main {
    public int lengthOfLongestSubstring(String s) {
        if(s.length()<=1){
            return s.length();
        }
        char[] arr=s.toCharArray();
        int max=0,start=0;
        Set<Character> set=new HashSet<Character>();
        for(int i=0;i<arr.length;i++){
            while(set.contains(arr[i])){
                set.remove(arr[start]);
                start++;
            }
            set.add(arr[i]);
            max=Math.max(max,set.size());
        }
        return max;
    }
    public int minSubArrayLen(int target, int[] nums) {
        if(nums.length==0){
            return 0;
        }
        int min=100001;
        int sum=0;
        int start=0,end=0;
        while(end<nums.length){
            sum+=nums[end];
            while(sum>=target){
                min=Math.min(min,end-start+1);
                sum-=nums[start];
                start++;
            }
            end++;
        }
        return min==100001?0:min;
    }
}